
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Dynamic Routing · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="ecs.html" />
    
    
    <link rel="prev" href="downfile.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="./">
            
                <a href="./">
            
                    
                    前端进阶
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="Grid System.html">
            
                <a href="Grid System.html">
            
                    
                    Grid System
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="Handwritten signature.html">
            
                <a href="Handwritten signature.html">
            
                    
                    Handwritten Signature
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="Mobile Soft Keyboard.html">
            
                <a href="Mobile Soft Keyboard.html">
            
                    
                    Mobile Soft Keyboard
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="authentication.html">
            
                <a href="authentication.html">
            
                    
                    Authentication
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" >
            
                <span>
            
                    
                    Code
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" >
            
                <span>
            
                    
                    Four Operations
            
                </span>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="control loading.html">
            
                <a href="control loading.html">
            
                    
                    Control Loading
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="downfile.html">
            
                <a href="downfile.html">
            
                    
                    Downfile
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.10" data-path="dynamic-routing.html">
            
                <a href="dynamic-routing.html">
            
                    
                    Dynamic Routing
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="ecs.html">
            
                <a href="ecs.html">
            
                    
                    Ecs
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="engineering.html">
            
                <a href="engineering.html">
            
                    
                    Engineering
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="eslint-vscode-format.html">
            
                <a href="eslint-vscode-format.html">
            
                    
                    Eslint Vscode Format
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="eventloop.html">
            
                <a href="eventloop.html">
            
                    
                    Eventloop
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="four-operations-1.html">
            
                <a href="four-operations-1.html">
            
                    
                    Four Operations 1
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16" data-path="four-operations-2.html">
            
                <a href="four-operations-2.html">
            
                    
                    Four Operations 2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17" data-path="four-operations-3.html">
            
                <a href="four-operations-3.html">
            
                    
                    Four Operations 3
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18" data-path="four-operations-4.html">
            
                <a href="four-operations-4.html">
            
                    
                    Four Operations 4
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.19" data-path="front end summary.html">
            
                <a href="front end summary.html">
            
                    
                    Front End Summary
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.20" data-path="git commit style.html">
            
                <a href="git commit style.html">
            
                    
                    Git Commit Style
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.21" data-path="git-commands.html">
            
                <a href="git-commands.html">
            
                    
                    Git Commands
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.22" data-path="high-quality-code.html">
            
                <a href="high-quality-code.html">
            
                    
                    High Quality Code
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.23" data-path="history.html">
            
                <a href="history.html">
            
                    
                    History
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.24" data-path="html-tag.html">
            
                <a href="html-tag.html">
            
                    
                    Html Tag
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.25" data-path="http-https-http2.html">
            
                <a href="http-https-http2.html">
            
                    
                    Http Https Http2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.26" data-path="ignore log.html">
            
                <a href="ignore log.html">
            
                    
                    Ignore Log
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.27" >
            
                <span>
            
                    
                    Imgs
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.28" data-path="javascript-optimization.html">
            
                <a href="javascript-optimization.html">
            
                    
                    Javascript Optimization
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.29" data-path="local application.html">
            
                <a href="local application.html">
            
                    
                    Local Application
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.30" data-path="locality.html">
            
                <a href="locality.html">
            
                    
                    Locality
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.31" data-path="loop-unrolling.html">
            
                <a href="loop-unrolling.html">
            
                    
                    Loop Unrolling
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.32" data-path="mobile recommendation.html">
            
                <a href="mobile recommendation.html">
            
                    
                    Mobile Recommendation
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.33" data-path="modal.html">
            
                <a href="modal.html">
            
                    
                    Modal
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.34" data-path="monitor.html">
            
                <a href="monitor.html">
            
                    
                    Monitor
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.35" data-path="performance.html">
            
                <a href="performance.html">
            
                    
                    Performance
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.36" data-path="print-talbe.html">
            
                <a href="print-talbe.html">
            
                    
                    Print Talbe
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.37" data-path="promise.html">
            
                <a href="promise.html">
            
                    
                    Promise
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.38" data-path="teaching.html">
            
                <a href="teaching.html">
            
                    
                    Teaching
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.39" data-path="vue refresh.html">
            
                <a href="vue refresh.html">
            
                    
                    Vue Refresh
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.40" data-path="vue-page-not-refresh.html">
            
                <a href="vue-page-not-refresh.html">
            
                    
                    Vue Page Not Refresh
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.41" data-path="why-learn-theory.html">
            
                <a href="why-learn-theory.html">
            
                    
                    Why Learn Theory
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >Dynamic Routing</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="vue-&#x52A8;&#x6001;&#x6DFB;&#x52A0;&#x8DEF;&#x7531;&#x53CA;&#x751F;&#x6210;&#x83DC;&#x5355;">Vue &#x52A8;&#x6001;&#x6DFB;&#x52A0;&#x8DEF;&#x7531;&#x53CA;&#x751F;&#x6210;&#x83DC;&#x5355;</h1>
<p>&#x5199;&#x540E;&#x53F0;&#x7BA1;&#x7406;&#x7CFB;&#x7EDF;&#xFF0C;&#x4F30;&#x8BA1;&#x6709;&#x4E0D;&#x5C11;&#x4EBA;&#x9047;&#x8FC7;&#x8FD9;&#x6837;&#x7684;&#x9700;&#x6C42;&#xFF1A;&#x6839;&#x636E;&#x540E;&#x53F0;&#x6570;&#x636E;&#x52A8;&#x6001;&#x6DFB;&#x52A0;&#x8DEF;&#x7531;&#x548C;&#x83DC;&#x5355;&#x3002;<br>
&#x4E3A;&#x4EC0;&#x4E48;&#x8FD9;&#x4E48;&#x505A;&#x5462;&#xFF1F;&#x56E0;&#x4E3A;&#x4E0D;&#x540C;&#x7684;&#x7528;&#x6237;&#x6709;&#x4E0D;&#x540C;&#x7684;&#x6743;&#x9650;&#xFF0C;&#x80FD;&#x8BBF;&#x95EE;&#x7684;&#x9875;&#x9762;&#x662F;&#x4E0D;&#x4E00;&#x6837;&#x7684;&#x3002;<br>
&#x5728;&#x7F51;&#x4E0A;&#x627E;&#x4E86;&#x597D;&#x591A;&#x8D44;&#x6599;&#xFF0C;&#x7EC8;&#x4E8E;&#x60F3;&#x5230;&#x4E86;&#x89E3;&#x51B3;&#x529E;&#x6CD5;&#x3002;<br></p>
<h3 id="&#x52A8;&#x6001;&#x751F;&#x6210;&#x8DEF;&#x7531;">&#x52A8;&#x6001;&#x751F;&#x6210;&#x8DEF;&#x7531;</h3>
<p>&#x5229;&#x7528; vue-router &#x7684; <code>addRoutes</code> &#x65B9;&#x6CD5;&#x53EF;&#x4EE5;&#x52A8;&#x6001;&#x6DFB;&#x52A0;&#x8DEF;&#x7531;&#x3002;</p>
<p>&#x5148;&#x770B;&#x4E00;&#x4E0B;&#x5B98;&#x65B9;&#x4ECB;&#x7ECD;&#xFF1A;</p>
<p><strong>router.addRoutes</strong></p>
<pre><code class="lang-js">router.addRoutes(routes: <span class="hljs-built_in">Array</span>&lt;RouteConfig&gt;)
</code></pre>
<p>&#x52A8;&#x6001;&#x6DFB;&#x52A0;&#x66F4;&#x591A;&#x7684;&#x8DEF;&#x7531;&#x89C4;&#x5219;&#x3002;&#x53C2;&#x6570;&#x5FC5;&#x987B;&#x662F;&#x4E00;&#x4E2A;&#x7B26;&#x5408; <code>routes</code> &#x9009;&#x9879;&#x8981;&#x6C42;&#x7684;&#x6570;&#x7EC4;&#x3002;</p>
<p>&#x4E3E;&#x4E2A;&#x4F8B;&#x5B50;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> router = <span class="hljs-keyword">new</span> Router({
    routes: [
        {
            path: <span class="hljs-string">&apos;/login&apos;</span>,
            name: <span class="hljs-string">&apos;login&apos;</span>,
            component: () =&gt; <span class="hljs-keyword">import</span>(<span class="hljs-string">&apos;../components/Login.vue&apos;</span>)
        },
        {path: <span class="hljs-string">&apos;/&apos;</span>, redirect: <span class="hljs-string">&apos;/home&apos;</span>},
    ]   
})
</code></pre>
<p>&#x4E0A;&#x9762;&#x7684;&#x4EE3;&#x7801;&#x548C;&#x4E0B;&#x9762;&#x7684;&#x4EE3;&#x7801;&#x6548;&#x679C;&#x662F;&#x4E00;&#x6837;&#x7684;</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> router = <span class="hljs-keyword">new</span> Router({
    routes: [
        {path: <span class="hljs-string">&apos;/&apos;</span>, redirect: <span class="hljs-string">&apos;/home&apos;</span>},
    ]   
})

router.addRoutes([
    {
        path: <span class="hljs-string">&apos;/login&apos;</span>,
        name: <span class="hljs-string">&apos;login&apos;</span>,
        component: () =&gt; <span class="hljs-keyword">import</span>(<span class="hljs-string">&apos;../components/Login.vue&apos;</span>)
    }
])
</code></pre>
<p>&#x5728;&#x52A8;&#x6001;&#x6DFB;&#x52A0;&#x8DEF;&#x7531;&#x7684;&#x8FC7;&#x7A0B;&#x4E2D;&#xFF0C;&#x5982;&#x679C;&#x6709; 404 &#x9875;&#x9762;&#xFF0C;&#x4E00;&#x5B9A;&#x8981;&#x653E;&#x5728;&#x6700;&#x540E;&#x6DFB;&#x52A0;&#xFF0C;&#x5426;&#x5219;&#x5728;&#x767B;&#x9646;&#x7684;&#x65F6;&#x5019;&#x6DFB;&#x52A0;&#x5B8C;&#x9875;&#x9762;&#x4F1A;&#x91CD;&#x5B9A;&#x5411;&#x5230; 404 &#x9875;&#x9762;&#x3002;</p>
<p>&#x7C7B;&#x4F3C;&#x4E8E;&#x8FD9;&#x6837;&#xFF0C;&#x8FD9;&#x79CD;&#x89C4;&#x5219;&#x4E00;&#x5B9A;&#x8981;&#x6700;&#x540E;&#x6DFB;&#x52A0;&#x3002;</p>
<pre><code class="lang-js">{path: <span class="hljs-string">&apos;*&apos;</span>, redirect: <span class="hljs-string">&apos;/404&apos;</span>}
</code></pre>
<h3 id="&#x52A8;&#x6001;&#x751F;&#x6210;&#x83DC;&#x5355;">&#x52A8;&#x6001;&#x751F;&#x6210;&#x83DC;&#x5355;</h3>
<p>&#x5047;&#x8BBE;&#x540E;&#x53F0;&#x8FD4;&#x56DE;&#x6765;&#x7684;&#x6570;&#x636E;&#x957F;&#x8FD9;&#x6837;</p>
<pre><code class="lang-js"><span class="hljs-comment">// &#x5DE6;&#x4FA7;&#x83DC;&#x5355;&#x680F;&#x6570;&#x636E;</span>
menuItems: [
    {
        name: <span class="hljs-string">&apos;home&apos;</span>, <span class="hljs-comment">// &#x8981;&#x8DF3;&#x8F6C;&#x7684;&#x8DEF;&#x7531;&#x540D;&#x79F0; &#x4E0D;&#x662F;&#x8DEF;&#x5F84;</span>
        size: <span class="hljs-number">18</span>, <span class="hljs-comment">// icon&#x5927;&#x5C0F;</span>
        type: <span class="hljs-string">&apos;md-home&apos;</span>, <span class="hljs-comment">// icon&#x7C7B;&#x578B;</span>
        text: <span class="hljs-string">&apos;&#x4E3B;&#x9875;&apos;</span> <span class="hljs-comment">// &#x6587;&#x672C;&#x5185;&#x5BB9;</span>
    },
    {
        text: <span class="hljs-string">&apos;&#x4E8C;&#x7EA7;&#x83DC;&#x5355;&apos;</span>,
        type: <span class="hljs-string">&apos;ios-paper&apos;</span>,
        children: [
            {
                type: <span class="hljs-string">&apos;ios-grid&apos;</span>,
                name: <span class="hljs-string">&apos;t1&apos;</span>,
                text: <span class="hljs-string">&apos;&#x8868;&#x683C;&apos;</span>
            },
            {
                text: <span class="hljs-string">&apos;&#x4E09;&#x7EA7;&#x83DC;&#x5355;&apos;</span>,
                type: <span class="hljs-string">&apos;ios-paper&apos;</span>,
                children: [
                    {
                        type: <span class="hljs-string">&apos;ios-notifications-outline&apos;</span>,
                        name: <span class="hljs-string">&apos;msg&apos;</span>,
                        text: <span class="hljs-string">&apos;&#x67E5;&#x770B;&#x6D88;&#x606F;&apos;</span>
                    },
                    {
                        type: <span class="hljs-string">&apos;md-lock&apos;</span>,
                        name: <span class="hljs-string">&apos;password&apos;</span>,
                        text: <span class="hljs-string">&apos;&#x4FEE;&#x6539;&#x5BC6;&#x7801;&apos;</span>
                    },
                    {
                        type: <span class="hljs-string">&apos;md-person&apos;</span>,
                        name: <span class="hljs-string">&apos;userinfo&apos;</span>,
                        text: <span class="hljs-string">&apos;&#x57FA;&#x672C;&#x8D44;&#x6599;&apos;</span>,
                    }
                ]
            }
        ]
    }
]
</code></pre>
<p>&#x6765;&#x770B;&#x770B;&#x600E;&#x4E48;&#x5C06;&#x5B83;&#x8F6C;&#x5316;&#x4E3A;&#x83DC;&#x5355;&#x680F;&#xFF0C;&#x6211;&#x5728;&#x8FD9;&#x91CC;&#x4F7F;&#x7528;&#x4E86; <code>iview</code> &#x7684;&#x7EC4;&#x4EF6;&#xFF0C;&#x4E0D;&#x7528;&#x91CD;&#x590D;&#x9020;&#x8F6E;&#x5B50;&#x3002;</p>
<pre><code class="lang-html"><span class="hljs-comment">&lt;!-- &#x83DC;&#x5355;&#x680F; --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">Menu</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;asideMenu&quot;</span> <span class="hljs-attr">theme</span>=<span class="hljs-string">&quot;dark&quot;</span> <span class="hljs-attr">width</span>=<span class="hljs-string">&quot;100%&quot;</span> @<span class="hljs-attr">on-select</span>=<span class="hljs-string">&quot;gotoPage&quot;</span> 
<span class="hljs-attr">accordion</span> <span class="hljs-attr">:open-names</span>=<span class="hljs-string">&quot;openMenus&quot;</span> <span class="hljs-attr">:active-name</span>=<span class="hljs-string">&quot;currentPage&quot;</span> @<span class="hljs-attr">on-open-change</span>=<span class="hljs-string">&quot;menuChange&quot;</span>&gt;</span>
    <span class="hljs-comment">&lt;!-- &#x52A8;&#x6001;&#x83DC;&#x5355; --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">v-for</span>=<span class="hljs-string">&quot;(item, index) in menuItems&quot;</span> <span class="hljs-attr">:key</span>=<span class="hljs-string">&quot;index&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">Submenu</span> <span class="hljs-attr">v-if</span>=<span class="hljs-string">&quot;item.children&quot;</span> <span class="hljs-attr">:name</span>=<span class="hljs-string">&quot;index&quot;</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">template</span> <span class="hljs-attr">slot</span>=<span class="hljs-string">&quot;title&quot;</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">Icon</span> <span class="hljs-attr">:size</span>=<span class="hljs-string">&quot;item.size&quot;</span> <span class="hljs-attr">:type</span>=<span class="hljs-string">&quot;item.type&quot;</span>/&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">v-show</span>=<span class="hljs-string">&quot;isShowAsideTitle&quot;</span>&gt;</span>{{item.text}}<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">template</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">v-for</span>=<span class="hljs-string">&quot;(subItem, i) in item.children&quot;</span> <span class="hljs-attr">:key</span>=<span class="hljs-string">&quot;index + i&quot;</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">Submenu</span> <span class="hljs-attr">v-if</span>=<span class="hljs-string">&quot;subItem.children&quot;</span> <span class="hljs-attr">:name</span>=<span class="hljs-string">&quot;index + &apos;-&apos; + i&quot;</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">template</span> <span class="hljs-attr">slot</span>=<span class="hljs-string">&quot;title&quot;</span>&gt;</span>
                        <span class="hljs-tag">&lt;<span class="hljs-name">Icon</span> <span class="hljs-attr">:size</span>=<span class="hljs-string">&quot;subItem.size&quot;</span> <span class="hljs-attr">:type</span>=<span class="hljs-string">&quot;subItem.type&quot;</span>/&gt;</span>
                        <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">v-show</span>=<span class="hljs-string">&quot;isShowAsideTitle&quot;</span>&gt;</span>{{subItem.text}}<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
                    <span class="hljs-tag">&lt;/<span class="hljs-name">template</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">MenuItem</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;menu-level-3&quot;</span> <span class="hljs-attr">v-for</span>=<span class="hljs-string">&quot;(threeItem, k) in subItem.children&quot;</span> <span class="hljs-attr">:name</span>=<span class="hljs-string">&quot;threeItem.name&quot;</span> <span class="hljs-attr">:key</span>=<span class="hljs-string">&quot;index + i + k&quot;</span>&gt;</span>
                        <span class="hljs-tag">&lt;<span class="hljs-name">Icon</span> <span class="hljs-attr">:size</span>=<span class="hljs-string">&quot;threeItem.size&quot;</span> <span class="hljs-attr">:type</span>=<span class="hljs-string">&quot;threeItem.type&quot;</span>/&gt;</span>
                        <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">v-show</span>=<span class="hljs-string">&quot;isShowAsideTitle&quot;</span>&gt;</span>{{threeItem.text}}<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
                    <span class="hljs-tag">&lt;/<span class="hljs-name">MenuItem</span>&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-name">Submenu</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">MenuItem</span> <span class="hljs-attr">v-else</span> <span class="hljs-attr">v-show</span>=<span class="hljs-string">&quot;isShowAsideTitle&quot;</span> <span class="hljs-attr">:name</span>=<span class="hljs-string">&quot;subItem.name&quot;</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">Icon</span> <span class="hljs-attr">:size</span>=<span class="hljs-string">&quot;subItem.size&quot;</span> <span class="hljs-attr">:type</span>=<span class="hljs-string">&quot;subItem.type&quot;</span>/&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">v-show</span>=<span class="hljs-string">&quot;isShowAsideTitle&quot;</span>&gt;</span>{{subItem.text}}<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-name">MenuItem</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">Submenu</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">MenuItem</span> <span class="hljs-attr">v-else</span> <span class="hljs-attr">:name</span>=<span class="hljs-string">&quot;item.name&quot;</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">Icon</span> <span class="hljs-attr">:size</span>=<span class="hljs-string">&quot;item.size&quot;</span> <span class="hljs-attr">:type</span>=<span class="hljs-string">&quot;item.type&quot;</span> /&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">v-show</span>=<span class="hljs-string">&quot;isShowAsideTitle&quot;</span>&gt;</span>{{item.text}}<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">MenuItem</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">Menu</span>&gt;</span>
</code></pre>
<p>&#x4EE3;&#x7801;&#x4E0D;&#x7528;&#x770B;&#x5F97;&#x592A;&#x4ED4;&#x7EC6;&#xFF0C;&#x7406;&#x89E3;&#x539F;&#x7406;&#x5373;&#x53EF;&#xFF0C;&#x5176;&#x5B9E;&#x5C31;&#x662F;&#x901A;&#x8FC7;&#x4E09;&#x6B21; <code>v-for</code> &#x4E0D;&#x505C;&#x7684;&#x5BF9;&#x5B50;&#x6570;&#x7EC4;&#x8FDB;&#x884C;&#x5FAA;&#x73AF;&#xFF0C;&#x751F;&#x6210;&#x4E09;&#x7EA7;&#x83DC;&#x5355;&#x3002;</p>
<p>&#x52A8;&#x6001;&#x83DC;&#x5355;&#x8FD9;&#x6837;&#x5C31;&#x53EF;&#x4EE5;&#x5B9E;&#x73B0;&#x4E86;&#x3002;</p>
<p><strong>&#x52A8;&#x6001;&#x8DEF;&#x7531;</strong>&#xFF0C;&#x56E0;&#x4E3A;&#x4E0A;&#x9762;&#x5DF2;&#x7ECF;&#x8BF4;&#x8FC7;&#x4E86;&#x7528; <code>addRoutes</code> &#x6765;&#x5B9E;&#x73B0;&#xFF0C;&#x73B0;&#x5728;&#x770B;&#x770B;&#x5177;&#x4F53;&#x600E;&#x4E48;&#x505A;&#x3002;</p>
<p>&#x9996;&#x5148;&#xFF0C;&#x8981;&#x628A;&#x9879;&#x76EE;&#x6240;&#x6709;&#x7684;&#x9875;&#x9762;&#x8DEF;&#x7531;&#x90FD;&#x5217;&#x51FA;&#x6765;&#xFF0C;&#x518D;&#x7528;&#x540E;&#x53F0;&#x8FD4;&#x56DE;&#x6765;&#x7684;&#x6570;&#x636E;&#x52A8;&#x6001;&#x5339;&#x914D;&#xFF0C;&#x80FD;&#x5339;&#x914D;&#x4E0A;&#x7684;&#x5C31;&#x628A;&#x8DEF;&#x7531;&#x52A0;&#x4E0A;&#xFF0C;&#x4E0D;&#x80FD;&#x5339;&#x914D;&#x4E0A;&#x7684;&#x5C31;&#x4E0D;&#x52A0;&#x3002;
&#x6700;&#x540E;&#x628A;&#x8FD9;&#x4E2A;&#x65B0;&#x751F;&#x6210;&#x7684;&#x8DEF;&#x7531;&#x6570;&#x636E;&#x7528; <code>addRoutes</code> &#x6DFB;&#x52A0;&#x5230;&#x8DEF;&#x7531;&#x8868;&#x91CC;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> asyncRoutes = {
    <span class="hljs-string">&apos;home&apos;</span>: {
        path: <span class="hljs-string">&apos;home&apos;</span>,
        name: <span class="hljs-string">&apos;home&apos;</span>,
        component: () =&gt; <span class="hljs-keyword">import</span>(<span class="hljs-string">&apos;../views/Home.vue&apos;</span>)
    },
    <span class="hljs-string">&apos;t1&apos;</span>: {
        path: <span class="hljs-string">&apos;t1&apos;</span>,
        name: <span class="hljs-string">&apos;t1&apos;</span>,
        component: () =&gt; <span class="hljs-keyword">import</span>(<span class="hljs-string">&apos;../views/T1.vue&apos;</span>)
    },
    <span class="hljs-string">&apos;password&apos;</span>: {
        path: <span class="hljs-string">&apos;password&apos;</span>,
        name: <span class="hljs-string">&apos;password&apos;</span>,
        component: () =&gt; <span class="hljs-keyword">import</span>(<span class="hljs-string">&apos;../views/Password.vue&apos;</span>)
    },
    <span class="hljs-string">&apos;msg&apos;</span>: {
        path: <span class="hljs-string">&apos;msg&apos;</span>,
        name: <span class="hljs-string">&apos;msg&apos;</span>,
        component: () =&gt; <span class="hljs-keyword">import</span>(<span class="hljs-string">&apos;../views/Msg.vue&apos;</span>)
    },
    <span class="hljs-string">&apos;userinfo&apos;</span>: {
        path: <span class="hljs-string">&apos;userinfo&apos;</span>,
        name: <span class="hljs-string">&apos;userinfo&apos;</span>,
        component: () =&gt; <span class="hljs-keyword">import</span>(<span class="hljs-string">&apos;../views/UserInfo.vue&apos;</span>)
    }
}

<span class="hljs-comment">// &#x4F20;&#x5165;&#x540E;&#x53F0;&#x6570;&#x636E; &#x751F;&#x6210;&#x8DEF;&#x7531;&#x8868;</span>
menusToRoutes(menusData)

<span class="hljs-comment">// &#x5C06;&#x83DC;&#x5355;&#x4FE1;&#x606F;&#x8F6C;&#x6210;&#x5BF9;&#x5E94;&#x7684;&#x8DEF;&#x7531;&#x4FE1;&#x606F; &#x52A8;&#x6001;&#x6DFB;&#x52A0;</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">menusToRoutes</span>(<span class="hljs-params">data</span>) </span>{
    <span class="hljs-keyword">const</span> result = []
    <span class="hljs-keyword">const</span> children = []

    result.push({
        path: <span class="hljs-string">&apos;/&apos;</span>,
        component: () =&gt; <span class="hljs-keyword">import</span>(<span class="hljs-string">&apos;../components/Index.vue&apos;</span>),
        children,
    })

    data.forEach(item =&gt; {
        generateRoutes(children, item)
    })

    children.push({
        path: <span class="hljs-string">&apos;error&apos;</span>,
        name: <span class="hljs-string">&apos;error&apos;</span>,
        component: () =&gt; <span class="hljs-keyword">import</span>(<span class="hljs-string">&apos;../components/Error.vue&apos;</span>)
    })

    <span class="hljs-comment">// &#x6700;&#x540E;&#x6DFB;&#x52A0;404&#x9875;&#x9762; &#x5426;&#x5219;&#x4F1A;&#x5728;&#x767B;&#x9646;&#x6210;&#x529F;&#x540E;&#x8DF3;&#x5230;404&#x9875;&#x9762;</span>
    result.push(
        {path: <span class="hljs-string">&apos;*&apos;</span>, redirect: <span class="hljs-string">&apos;/error&apos;</span>},
    )

    <span class="hljs-keyword">return</span> result
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">generateRoutes</span>(<span class="hljs-params">children, item</span>) </span>{
    <span class="hljs-keyword">if</span> (item.name) {
        children.push(asyncRoutes[item.name])
    } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (item.children) {
        item.children.forEach(e =&gt; {
            generateRoutes(children, e)
        })
    }
}
</code></pre>
<p>&#x6240;&#x6709;&#x7684;&#x4EE3;&#x7801;&#x5B9E;&#x73B0;&#xFF0C;&#x6211;&#x90FD;&#x653E;&#x5728; <a href="https://github.com/woai3c/vue-admin-template" target="_blank">github</a> &#x4E0A;&#xFF0C;&#x52A8;&#x6001;&#x83DC;&#x5355;&#x7684;&#x5B9E;&#x73B0;&#x653E;&#x5728;&#x8FD9;&#x4E2A;&#x9879;&#x76EE;&#x4E0B;&#x7684; <code>src/components/Index.vue</code>&#x3001;<code>src/permission.js</code> &#x548C; <code>src/utils/index.js</code>&#x4E0B;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="downfile.html" class="navigation navigation-prev " aria-label="Previous page: Downfile">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="ecs.html" class="navigation navigation-next " aria-label="Next page: Ecs">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"Dynamic Routing","level":"1.10","depth":1,"next":{"title":"Ecs","level":"1.11","depth":1,"path":"前端进阶/ecs.md","ref":"前端进阶/ecs.md","articles":[]},"previous":{"title":"Downfile","level":"1.9","depth":1,"path":"前端进阶/downfile.md","ref":"前端进阶/downfile.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["summary","livereload"],"pluginsConfig":{"summary":{},"livereload":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"前端进阶/dynamic-routing.md","mtime":"2021-02-15T12:04:36.000Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-03-24T08:50:55.666Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

